home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / headers / dtscpluslibrary.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  7.0 KB  |  267 lines

  1. /*
  2.     File:        DTSCPlusLibrary.h
  3.  
  4.     Contains:    DTSCPlusLibrary.h contains all the global data and definitions needed when building
  5.                   more DTS C++ libraries. Every class should have this file included.
  6.                   DTSLibrary.h contains all the header information.
  7.  
  8.     Written by:     
  9.  
  10.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.                 You may incorporate this Apple sample source code into your program(s) without
  13.                 restriction. This Apple sample source code has been provided "AS IS" and the
  14.                 responsibility for its operation is yours. You are not permitted to redistribute
  15.                 this Apple sample source code as "Apple sample source code" after having made
  16.                 changes. If you're going to re-distribute the source, we require that you make
  17.                 it clear in the source that the code was descended from Apple sample source
  18.                 code, but that you've made changes.
  19.  
  20.     Change History (most recent first):
  21.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  22.                 
  23.  
  24. */
  25. // Declare label for this header file
  26. #ifndef _DTSCPLUSLIBRARY_
  27. #define _DTSCPLUSLIBRARY_
  28.  
  29.  
  30. // _________________________________________________________________________________________________________ //
  31. // GLOBAL DEFINITIONS
  32.  
  33. // TESTING, used for flagging that we use test code inside the classes and frameworks
  34. // TESTLEVEL0        - user friendly alerts as part of the application
  35. // TESTLEVEL1     - minor test level (detailed error message in alert box)
  36. // TESTLEVEL2     - semi-major test level (high level debuggers)
  37. // TESTLEVEL3     - major test level (low level debuggers)
  38. // future: TESTLOG1        - trigger a file log of information
  39. //            TESTLOG2        - trigger a file log of information from a low level debugger
  40.  
  41. #define TESTLEVEL3
  42.  
  43. // MPW C++, 1 = code for MPW C++
  44. // #define MPWC++ 
  45.  
  46. // ZTC, 1 = code for ZTC
  47. // #define ZTC 
  48.  
  49. // SLM, code used with Shared Library Manager Support, 1 = true
  50. // #define SLM 
  51.  
  52. // _________________________________________________________________________________________________________ //
  53. // GENERAL INCLUDE FILES
  54.  
  55. //    Toolbox Include Files
  56. #ifndef __TYPES__
  57. #include <Types.h>
  58. #endif
  59.  
  60. #ifndef __STRING__
  61. #include <String.h>
  62. #endif
  63.  
  64. #ifndef __MEMORY__
  65. #include <Memory.h>
  66. #endif
  67.  
  68. #ifndef __DIALOGS__
  69. #include <Dialogs.h>
  70. #endif
  71.  
  72. #ifndef __APPLEEVENTS__
  73. #include <AppleEvents.h>
  74. #endif
  75.  
  76. // C++ library code
  77. #include <iostream.h>
  78. #include <stdlib.h>
  79. #include <StdIO.h>
  80. #include <stdarg.h>
  81.  
  82. #ifdef SLM
  83. #include <LibraryManagerClasses.h>
  84. #endif
  85.  
  86. // FUNCTION PROTOTYPES
  87. // I found out that these following former inlined functions were not inlined,
  88. // the linker screamed, so they now live in a .cp file (sigh), remember to include
  89. // the CPlusLibrary.cp file when using the other .cp files!
  90.  
  91. short clen(char *cptr);
  92. void c2p(char *cptr);
  93. void p2c(StringPtr cptr);
  94. void Pstrcpy(StringPtr d, StringPtr s);
  95. void ConcatPStrings(Str255 first, Str255 second);
  96. Boolean CompareStr255(const Str255 *first, const Str255 *second);
  97.  
  98. void vxdebugstr(char* format,...);
  99.  
  100. void ErrorWindow(char* message);
  101.  
  102. // INLINE FUNCTIONS
  103. // _________________________________________________________________________________________________________ //
  104. // 1: BASIC MANIPULATION INLINES
  105.  
  106. // Min/Max functions, oh so useful.
  107. inline short Min(const short a,
  108.                  const short b)
  109. {
  110.     return a < b ? a : b;                        // Just returns the minimum of the two shorts.
  111. }                                                // Min 
  112.  
  113.  
  114. inline short Max(const short a,
  115.                  const short b)
  116. {
  117.     return a > b ? a : b;                        // Just returns the maximum of the two shorts.
  118. }                                                // Max 
  119.  
  120.  
  121. inline pascal    Byte Decimal2BCD(Byte n) 
  122. {
  123.     return ((n / 10) << 4) + (n % 10); 
  124. }
  125.  
  126. inline pascal    Byte BCD2Decimal(Byte n) 
  127. {
  128.     return ((n >> 4) * 10) + (n & 0x0f);
  129. }
  130.  
  131. // extract hi word and lo word from a longword
  132. #define HiWrd(aLong)        ((short) (((aLong) >> 16) & 0xFFFF)) 
  133. #define LoWrd(aLong)        ((short) ((aLong) & 0xFFFF)) 
  134.  
  135.  
  136.  
  137. // _________________________________________________________________________________________________________ //
  138. // MACROS AND DEBUGGING
  139. // ASSERT Function, used for testing conditions and flagging error states.
  140. // Example: vdebugstr("The error message from Foo is %i", fError);
  141.  
  142. // We need to load in certain include files if we want to use the alert boxes for
  143. // high level ASSERT functions (we also need to include the GUIApplication.r file
  144. // into the project).
  145.  
  146. #if (defined TESTLEVEL0 || defined TESTLEVEL1)
  147. #include "ApplicationResources.h"
  148. #endif
  149.  
  150.  
  151. //  Define this flag if you want file and line information as part of the message.
  152. #define FILELINEINFO
  153.  
  154.  
  155. //     fileinfo will keep track of the current file and line in a global.
  156. static char fileNameArray[32];
  157. static char lineNumberArray[32];
  158.  
  159.  
  160. #if (defined TESTLEVEL0 || defined TESTLEVEL1)
  161. inline void AlertUser(Str255 theMessage)
  162. {
  163.     short itemHit;
  164.     
  165.     if(!(AEInteractWithUser(kNoTimeOut, nil, nil)))                // could we interact with the user?
  166.     {
  167.         ParamText(theMessage, 0, 0,0);
  168.         itemHit = Alert(kUserAlert, nil);
  169.     }
  170. }
  171. #endif
  172.  
  173. inline void fileinfo(char *file, int line)
  174. {
  175.     sprintf(fileNameArray, "File %s ", file);
  176.     sprintf(lineNumberArray, " Line %d  #", line);
  177. }
  178.  
  179.  
  180.  
  181.  
  182. //    ASSERT MACROS
  183.  
  184. //    ASSERT, small (and quick assert),  if assertion is false it will print out 
  185. //     a message
  186. //    Use: ASSERT(false, "Problems with TSoundRecorder");
  187.  
  188. #if (defined TESTLEVEL0 || defined TESTLEVEL1)
  189. #define ASSERT(condition,debugMsg) do {                        \
  190.     if(condition == 0)                                        \
  191.     {                                                        \
  192.         AlertUser(debugMsg);                                \
  193.     }                                                        \
  194.    } while (0)                                                \
  195.  
  196. #elif (defined TESTLEVEL2 || defined TESTLEVEL3)
  197. #define ASSERT(condition,debugMsg) do {                        \
  198.     if(condition == 0)                                        \
  199.     {                                                        \
  200.         DebugStr(debugMsg);                                    \
  201.     }                                                        \
  202.    } while (0)
  203. #else
  204. #define ASSERT(condition,debugMsg) ((void) 0)
  205. #endif
  206.  
  207.  
  208. //    VASSERT, if assertion is false it will print out file, line, message and possible variable
  209. //    Use: VASSERT(false,("Problems with %d", anErr));
  210.  
  211. #if (defined TESTLEVEL0)
  212. ##define VASSERT(condition,debugMsg) do {                    \
  213.     if(condition == 0)                                        \
  214.     {                                                        \
  215.         vxdebugstr  debugMsg;                                \
  216.     }                                                        \
  217.    } while (0)
  218.  
  219. #elif (defined TESTLEVEL1 || defined TESTLEVEL2 ||  defined TESTLEVEL3)
  220. #define VASSERT(condition,debugMsg) do {                    \
  221.     if(condition == 0)                                        \
  222.     {                                                        \
  223.         fileinfo(__FILE__, __LINE__);                        \
  224.         vxdebugstr  debugMsg;                                \
  225.     }                                                        \
  226.    } while (0)
  227.    
  228. #else
  229. #define (condition,debugMsg) ((void) 0)
  230. #endif
  231.  
  232.  
  233. // Option key triggered debug breaks:
  234. inline void ODebugger()
  235. // Drop into Debugger only if the option key is pressed.
  236. {
  237.     KeyMap k;
  238.     GetKeys(k);
  239.     if (((char*)k)[7] & 0x04)                    // check for option key in KeyMap
  240.         Debugger();
  241. }
  242.  
  243.  
  244. inline void ODebugStr(Str255 string)
  245. // Drop into DebugStr only if the option key is pressed.
  246. {
  247.     KeyMap k;
  248.     GetKeys(k);
  249.     if (((char*)k)[7] & 0x04)                    // check for option key in KeyMap
  250.         DebugStr(string);
  251. }
  252.  
  253.  
  254. #endif
  255.  
  256. // _________________________________________________________________________________________________________ //
  257.  
  258.  
  259. /*    Change History (most recent last):
  260.   No    Init.    Date        Comment
  261.   1        khs        9/10/92        New file
  262.   2        khs        11/26/92    Added ASSERT macros and testing levels
  263.   3        khs        1/14/93        Cleanup
  264. */
  265.  
  266.  
  267.